<?php
namespace app\index\controller;

use think\Controller;
class Share extends Controller
{
    function index(){
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
//            echo 'systerm is IOS';
            $type=1;
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
//            echo 'systerm is Android';
            $type=2;
        }else{
//            echo 'systerm is other';
            $type=2;
        }
        $id=request()->get('id');
        $system=db('system')->find();
        if($type==1){
            $url=$system['ios_url'];
        }else if($type==2){
            $url=$system['android_url'];
        }
        $goods=db('goods a')
            ->where(array('a.g_id' => $id))
            ->find();
        $img = db("goods_img")
            ->where(array('g_id' => $id, 'gi_status' => 1))
            ->order("gi_sort desc")
            ->find();
        $norm = db("goods_norm a")
            ->field("a.g_id,a.gn_id,a.gn_name,a.gn_weight,a.gn_price,a.gn_one_number,a.gn_sort,a.gn_stock,a.gn_old_price")
            ->where(array('a.g_id' => $id, 'a.gn_status' => 1))
            ->order("a.gn_sort desc")
            ->select();
//        dump($goods);
//        dump($norm);die;
        $this->assign('goods',$goods);
        $this->assign('img',$img);
        $this->assign('norm',$norm);
        $this->assign('url',$url);
        return view();
    }
}